package cn.liyunqi.ttv.web.controller;

import cn.liyunqi.ttv.web.service.CommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/")
public class MainController {

    @Autowired
    private CommonService commonService;

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index( ModelMap model) {
        return "index";
    }
    @RequestMapping(value = "/download", method = RequestMethod.GET)
    public String download( ModelMap model) {
        String downloadZipUrl = commonService.getDownloadZipUrl();
        model.addAttribute("downloadZipUrl", downloadZipUrl);
        return "download";
    }

    @RequestMapping(value = "/{name}", method = RequestMethod.GET)
    public String getMovie(@PathVariable String name, ModelMap model) {
        model.addAttribute("name", name);
        model.addAttribute("query", "");
        model.addAttribute("submit", "");
        return "index";
    }


    @RequestMapping(value = "/query", method = RequestMethod.GET)
    public String query(@RequestParam("name") String name, ModelMap model) {
        model.addAttribute("name", "");
        model.addAttribute("query", name);
        model.addAttribute("submit", "");
        return "index";
    }

    @RequestMapping(value = "/submit", method = RequestMethod.GET)
    public String submit(@RequestParam("name") String name, ModelMap model) {
        model.addAttribute("name", "");
        model.addAttribute("query", "");
        model.addAttribute("submit", name);
        return "index";
    }
}
